﻿using StudySystem.MainLogic;
using StudySystem.MainLogic.Items;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StudySystem.SQLServer
{
    public static class DBForRecord
    {
        /// <summary>
        /// 获得指定问题的所有记录
        /// </summary>
        /// <param name="questionID"></param>
        public static DataAdapter SelectAllRecords(ref DataSet ds, string questionID)
        {
            string sql = "select SubjectID,QuestionID,Result,Date " +
                "from RecordTable where UserID = " + UserManagement.user.UserID + " and QuestionID = " + questionID;
            return DbHelper.GetTable(sql, ref ds, "recordTable");
        }

        public static int InsertARecord(string subjectID, string questionID, AnswerResult result)
        {
            string sql = "insert into RecordTable(UserID,SubjectID,QuestionID,Result) " +
                "values(@userID,@subjectID,@questionID,@result)";
            SqlParameter paraUserID = new SqlParameter("@userID", SqlDbType.NChar);
            paraUserID.Value = UserManagement.user.UserID;
            SqlParameter paraSubID = new SqlParameter("@subjectID", SqlDbType.Int);
            paraSubID.Value = subjectID;
            SqlParameter paraQuesID = new SqlParameter("@questionID", SqlDbType.Int);
            paraQuesID.Value = questionID;
            SqlParameter paraAnsResult = new SqlParameter("@result", SqlDbType.Int);
            paraAnsResult.Value = result;
            return DbHelper.SafeExecuteNonQuery(sql, paraUserID, paraSubID, paraQuesID, paraAnsResult);
        }

    }
}
